import car from '../../config/api/car' // 引入api接口管理文件
var WxNotificationCenter = require("../../config/WxNotificationCenter");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    startTime: null,
    endTime: null,
    selectcar: false,
    conferenceList: [{
      name: "加载中"
    }],
  },
  loadData() {
    let vm = this;
    let obj = {
      "pageNo": 1,
      "pageSize": 9999
    };
    if (this.data.startTime) {
      obj["startTime"] = this.data.startTime;
      obj["endTime"] = this.data.endTime;
    }
    //加载车辆列表
    car.list(obj, function (res) {
      let list = res.data.data.records;
      vm.setData({
        conferenceList: list
      })
    })
  },
  clickitem(e) {
    let index = e.currentTarget.dataset.item;
    if (this.data.selectcar) {
      let item = this.data.conferenceList[index];
      WxNotificationCenter.postNotificationName("selectcar", item);
      wx.navigateBack({
        delta: 1,
      })
      return;
    }
    wx.redirectTo({
      url: './appointment/appointment?list=' + JSON.stringify(this.data.conferenceList) + "&selectindex=" + index,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if (options.selectcar) {
      this.setData({
        selectcar: options.selectcar
      })
      if (options.startTime && options.endTime) {
        this.setData({
          startTime: options.startTime,
          endTime: options.endTime,
        })
      }
    }
    var that = this
    WxNotificationCenter.addNotification('getcarlist', that.loadData, that)
    this.loadData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
    var that = this
    WxNotificationCenter.removeNotification('getcarlist', that);
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})